1
|
|
|
export interface PenthouseConfig { |
2
|
|
|
/** Accessible url. Use file:/// protocol for local html files. */ |
3
|
|
|
url: string; |
4
|
|
|
/** Original css to extract critical css from */ |
5
|
|
|
cssString: string; |
6
|
|
|
/** Path to original css file on disk (if using instead of `cssString`) */ |
7
|
|
|
css: string; |
8
|
|
|
/** Width for critical viewport */ |
9
|
|
|
width: number; |
10
|
|
|
/** Height for critical viewport */ |
11
|
|
|
height: number; |
12
|
|
|
/** Configuration for screenshots (not used by default). See [Screenshot example](https://github.com/pocketjoso/penthouse/blob/master/examples/screenshots.js) */ |
13
|
|
|
screenshots: object; |
14
|
|
|
/** Keep media queries even for width/height values larger than critical viewport. */ |
15
|
|
|
keepLargerMediaQueries: boolean; |
16
|
|
|
/** |
17
|
|
|
* Array of css selectors to keep in critical css, even if not appearing in critical viewport. |
18
|
|
|
* Strings or regex (f.e. `['.keepMeEvenIfNotSeenInDom', /^\.button/]`) |
19
|
|
|
*/ |
20
|
|
|
forceInclude: Array<string>; |
21
|
|
|
/** |
22
|
|
|
* Array of css selectors to remove in critical css, even if appearing in critical viewport. |
23
|
|
|
* Strings or regex (f.e. `['.doNotKeepMeEvenIfNotSeenInDom', /^\.button/]`) |
24
|
|
|
*/ |
25
|
|
|
forceExclude: Array<string>; |
26
|
|
|
/** Css properties to filter out from critical css */ |
27
|
|
|
propertiesToRemove: Array<string>; |
28
|
|
|
/** Ms; abort critical CSS generation after this time */ |
29
|
|
|
timeout: number; |
30
|
|
|
/** Settings for puppeteer. See [Custom puppeteer browser example](https://github.com/pocketjoso/penthouse/blob/master/examples/custom-browser.js) */ |
31
|
|
|
puppeteer: object; |
32
|
|
|
/** Ms; stop waiting for page load after this time (for sites when page load event is unreliable) */ |
33
|
|
|
pageLoadSkipTimeout: number; |
34
|
|
|
/** |
35
|
|
|
* ms; wait time after page load before critical css extraction starts |
36
|
|
|
* (also before "before" screenshot is taken, if used) |
37
|
|
|
*/ |
38
|
|
|
renderWaitTime: number; |
39
|
|
|
/** set to false to load JS (not recommended) */ |
40
|
|
|
blockJSRequests: boolean; |
41
|
|
|
/** characters; strip out inline base64 encoded resources larger than this */ |
42
|
|
|
maxEmbeddedBase64Length: number; |
43
|
|
|
/** Can be specified to limit nr of elements to inspect per css selector, reducing execution time. */ |
44
|
|
|
maxElementsToCheckPerSelector: number; |
45
|
|
|
/** specify which user agent string when loading the page */ |
46
|
|
|
userAgent: string; |
47
|
|
|
/** Set extra http headers to be sent with the request for the url. */ |
48
|
|
|
customPageHeaders: object; |
49
|
|
|
/** For formatting of each cookie, see [Puppeteer setCookie docs](https://github.com/puppeteer/puppeteer/blob/v1.9.0/docs/api.md#pagesetcookiecookies) */ |
50
|
|
|
cookies: Array<string>; |
51
|
|
|
/** Make Penthouse throw on errors parsing the original CSS. Legacy option, not recommended */ |
52
|
|
|
strict: boolean; |
53
|
|
|
/** |
54
|
|
|
* Let Penthouse stop if the server response code is not matching this value. number and |
55
|
|
|
* regex types are tested against the [response.status()](https://github.com/puppeteer/puppeteer/blob/v1.14.0/docs/api.md#responsestatus). A function is also allowed and |
56
|
|
|
* gets [Response](https://github.com/puppeteer/puppeteer/blob/v1.14.0/docs/api.md#class-response) as argument. The function should return a boolean. |
57
|
|
|
*/ |
58
|
|
|
allowedResponseCode: number | RegExp | Function; |
59
|
|
|
} |
60
|
|
|
import { PenthouseConfig } from './penthouse'; |
61
|
|
|
|
62
|
|
|
export type DeclCallback = (node: object, value: string) => boolean; |
63
|
|
|
|
64
|
|
|
export interface CriticalConfig { |
65
|
|
|
/** Inline critical-path CSS using filamentgroup's loadCSS. Pass an object to configure `inline-critical` */ |
66
|
|
|
inline: boolean; |
67
|
|
|
/** Base directory in which the source and destination are to be written */ |
68
|
|
|
base: string; |
69
|
|
|
/** HTML source to be operated against. This option takes precedence over the `src` option */ |
70
|
|
|
html: string; |
71
|
|
|
/** An array of paths to css files, file globs or Vinyl file objects. */ |
72
|
|
|
css: Array<string>; |
73
|
|
|
/** Location of the HTML source to be operated against */ |
74
|
|
|
src: string; |
75
|
|
|
/** |
76
|
|
|
* Location of where to save the output of an operation. |
77
|
|
|
* Use an object with 'html' and 'css' props if you want to store both |
78
|
|
|
*/ |
79
|
|
|
target: string | Partial<{ |
80
|
|
|
css: string; |
81
|
|
|
html: string; |
82
|
|
|
uncritical: string; |
83
|
|
|
}>; |
84
|
|
|
/** Width of the target viewport */ |
85
|
|
|
width: number; |
86
|
|
|
/** Height of the target viewport */ |
87
|
|
|
height: number; |
88
|
|
|
/** Enable minification of generated critical-path */ |
89
|
|
|
minify: boolean; |
90
|
|
|
/** |
91
|
|
|
* Remove the inlined styles from any stylesheets referenced in the HTML. |
92
|
|
|
* It generates new references based on extracted content so it's safe to use for |
93
|
|
|
* multiple HTML files referencing the same stylesheet. Use with caution. |
94
|
|
|
* Removing the critical CSS per page results in a unique async loaded CSS file for every page. |
95
|
|
|
* Meaning you can't rely on cache across multiple pages |
96
|
|
|
*/ |
97
|
|
|
extract: boolean; |
98
|
|
|
/** Inline images */ |
99
|
|
|
inlineImages: boolean; |
100
|
|
|
/** List of directories/urls where the inliner should start looking for assets */ |
101
|
|
|
assetPaths: Array<string>; |
102
|
|
|
/** Sets a max file size (in bytes) for base64 inlined images */ |
103
|
|
|
maxImageFileSize: number; |
104
|
|
|
/** |
105
|
|
|
* Critical tries it's best to rebase the asset paths relative to the document. |
106
|
|
|
* If this doesn't work as expected you can always use this option to control the rebase paths. |
107
|
|
|
* See postcss-url for details. (https://github.com/pocketjoso/penthouse#usage-1). |
108
|
|
|
*/ |
109
|
|
|
rebase: object | Function; |
110
|
|
|
/** ignore CSS rules */ |
111
|
|
|
ignore: Partial<{ |
112
|
|
|
atrule: Array<string>; |
113
|
|
|
rule: Array<string>; |
114
|
|
|
decl: DeclCallback; |
115
|
|
|
}>; |
116
|
|
|
/** User agent to use when fetching a remote src */ |
117
|
|
|
userAgent: string; |
118
|
|
|
/** Configuration options for `penthouse`. */ |
119
|
|
|
penthouse: Partial<PenthouseConfig>; |
120
|
|
|
/** Configuration options for `got`. */ |
121
|
|
|
request: object; |
122
|
|
|
/** RFC2617 basic authorization: `user` */ |
123
|
|
|
user: string; |
124
|
|
|
/** RFC2617 basic authorization: `pass` */ |
125
|
|
|
pass: string; |
126
|
|
|
/** Throw an error if no css is found */ |
127
|
|
|
strict: boolean; |
128
|
|
|
} |
129
|
|
|
import { CriticalConfig } from './critical'; |
130
|
|
|
|
131
|
|
|
export interface CriticalPages { |
132
|
|
|
/** Combined with `criticalUrl` to determine the URLs to scrape for Critical CSS */ |
133
|
|
|
uri: string; |
134
|
|
|
/** Critical CSS files are named with the `template` path, and saved to the `criticalBase` directory */ |
135
|
|
|
template: string; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
export interface CriticalPluginConfig { |
139
|
|
|
/** |
140
|
|
|
* The base URL to use in combination with the `criticalPages` `uri`s to determine the URLs to scrape for Critical CSS. |
141
|
|
|
* This can also be a file system path. This is combined with `criticalPages.uri` |
142
|
|
|
* to determine pages to scrap for critical CSS. |
143
|
|
|
* Determines the `criticalConfig.src` property |
144
|
|
|
*/ |
145
|
|
|
criticalUrl: string; |
146
|
|
|
/** |
147
|
|
|
* The base file system path to where the generated Critical CSS file should be saved. |
148
|
|
|
* This is combined with `criticalPages.template` with `_critical.min.css` appended |
149
|
|
|
* to it to determine the saved critical CSS file name. |
150
|
|
|
* Determines the `criticalConfig.target` property |
151
|
|
|
*/ |
152
|
|
|
criticalBase?: string; |
153
|
|
|
/** |
154
|
|
|
* An array objects that contain the page `uri`s that are combined with the `criticalUrl` to |
155
|
|
|
* determine the URLs to scrape for Critical CSS. The resulting files are named with the |
156
|
|
|
* `template` path, and saved to the `criticalBase` directory |
157
|
|
|
*/ |
158
|
|
|
criticalPages: Partial<CriticalPages>[]; |
159
|
|
|
/** |
160
|
|
|
* This is the full [config for critical](https://github.com/addyosmani/critical#options) that is passed |
161
|
|
|
* through to the `critical` package. |
162
|
|
|
* You may optionally override any properties you like here |
163
|
|
|
*/ |
164
|
|
|
criticalConfig?: Partial<CriticalConfig>; |
165
|
|
|
} |
166
|
|
|
|